﻿using Coffee_Restaurant.Forms;
using Coffee_Restaurant.Forms.AreaTable;
using Coffee_Restaurant.Forms.InOutMoneys;
using Coffee_Restaurant.Forms.Items;
using System;
using System.ComponentModel;
using System.Configuration;
using System.Windows.Forms;

namespace Coffee_Restaurant
{
    public partial class MainForm : Form
    {
        private DisplayListTable _listTable;

        public MainForm()
        {
            InitializeComponent();

        }
        //esc to exit
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == Keys.Escape)
            {
                this.Close();
                return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        private void btn_Click(object sender, EventArgs e)
        {
            var button = sender as Button;
            if (button != null)
                switch (button.Name)
                {
                    case "btnClose":
                        this.Close();
                        break;
                    case "btnMini":
                        this.WindowState = FormWindowState.Minimized;
                        break;
                }
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            backgroundWorker1.RunWorkerAsync();

        }

        void areaTable_FormClosing(object sender, FormClosingEventArgs e)
        {
            _listTable.LoadDataArea();
        }
        private void ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var menu = sender as ToolStripMenuItem;
            if (menu != null)
                switch (menu.Name)
                {
                    case "managerareanumber":
                        //add form quan ly ban vao panel
                        var areaTable = new ManagerAreaTable();
                        areaTable.FormClosing += areaTable_FormClosing;
                        areaTable.ShowDialog();
                        break;
                    case "btnMini":
                        break;
                }
        }

        private void tHỰCĐƠNToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void kHUVỰCBÀNToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //add form quan ly ban vao panel
            var areaTable = new ManagerAreaTable();
            areaTable.FormClosing += areaTable_FormClosing;
            areaTable.ShowDialog();
        }

        private void pHÂNQUYỀNQUẢNLÝToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var frm = new ManagerPermission();
            frm.ShowDialog();
        }

        private void thựcĐơnToolStripMenuItem1_Click(object sender, EventArgs e)
        {

        }

        void LoadPanelLeft()
        {
            _listTable = new DisplayListTable { Dock = DockStyle.Fill };
            //config
            int sizeTableNumber = Convert.ToInt32(ConfigurationManager.AppSettings["SizeTableNumber"]);
            int columnTable = Convert.ToInt32(ConfigurationManager.AppSettings["ColumnTable"]);
            int reConfigWidth = (sizeTableNumber + 25) * columnTable;
            panelLeft.Width = reConfigWidth;
            panelLeft.Controls.Add(_listTable);
            _listTable.Visible = true;
        }

        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            //LoadPanelLeft();
        }

        private void thuChiToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new ManagerInOutMoneys().ShowDialog();
        }

        private void càiĐặtMáyInToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new ManagerPrinter().ShowDialog();
        }

        private void thựcĐơnToolStripMenuItem2_Click(object sender, EventArgs e)
        {

        }

    }
}
